home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 4
/
Precision Software Applications Silver Collection Volume 4 (1993).iso
/
stats
/
chadyn.exe
/
YPLOT.C
< prev
next >
Wrap
Text File
|
1988-12-12
|
52KB
|
1,923 lines
/******************* (C) 1986,7,8 by JAMES A. YORKE **************************/
/******************************** YPLOT.C ***********************************/
/* This file YPLOT.C contains routines that are tools
for plotting on the screen and in the core
James Yorke */
/* Routines in YPLOT.c
These are routines that are essentially independent of the map being studied.
add_to_pic in YDISK.C
block_plot(x1,x2,y1,y2)
boot_crt
clearp
connectp(x,y) connects x,y to x_c,y_c
double x,y;
connect2(x1,y1,x2,y2)
cross(x1,y1,m,n,picnum,crossnum) reverses m dots on each side of screen point
(row,col) and n above and below; picnum = 1 means the
screen; = 2 means the core picture
double x1,y1; int m,n,picnum;
definitely_erase_line()
draw_box
erase_line()
fetchPic
fileFailureWarning()
FindPixel(x1,y1,picnum) this routine puts the coordinates in the
vector COL,ROW; if picnum == 1, they are for the crt while
if == 2 they are for the core copy
double x1,y1;int picnum;
maskdef
picOff(COLnum1,ROWnum1,COLnum2,ROWnum2)
int COLnum1,ROWnum1,COLnum2,ROWnum2;
td0 monochrome
td to disk
plot(x,y)
PlotComplaint
PrintBoxCoordinates() if printer > 1; prints at top of screen
pprint(onprint) in YPLOT2.C
resetDiameters
reverseCore(x,y)
ScreenConstants() sets ax,bx where x = 0,00,1,2
scrOff(COLnum1,ROWnum1,COLnum2,ROWnum2)
int COLnum1,ROWnum1,COLnum2,ROWnum2;
int set_box sets X_low thru Y_upp
double ticGap(dif) dif is double; called by ticMarks
ticMarks() called by draw_box when ticFlag == ON
*/
#include "yinclud.h"
/*#define DEBUG*/
#ifndef X11
#define BLANK 0
#ifdef DESMET
#define _setcolor(x) null(x)
#endif /* DESMET */
/* char far pic1[CORESIZE]; 65280 = Memory size in core */
char far *pic1 = NULL;
char far *pic2 = NULL;
char far *pic4 = NULL;
char far *pic8 = NULL;
char one = 1,
two = 2,
four = 4,
eight = 8; /* bytes for pic arrays */
unsigned char byte255 = 255;
/*unsigned char byteCount = 0;
*/
int byteCount = 0;
char lastByte;
FILE *fp, *gp; /* for disk i/o */
/* The core(i.e. pic1[]) and screen operations are independent */
/* #define ABS(x) ( (x)>0 ? x : -x) */
static int sROW,
sCOL;
int xmax,
ymax; /* set by FindPixel */
static double xCorPix[5],
yCorPix[5];
static double xDifRecip,
yDifRecip; /* set by screenConstants */
static int LeftScrEdge[5],
RtScrEdge[5],
TopScrEdge[5],
BotScrEdge[5];
/* note: ROW and COL are int in yextern.h */
#ifndef unix
#include <malloc.h> /* required only for function declarations */
#include <stdlib.h> /* for ANSI compatibility -- malloc only */
#endif /* unix */
static halfscrcols,
halfscrrows;
extern char printstatus; /* set in YPRINTER.C, = status byte of printer;
see also _bios_printer() which is a MSC
function */
char far *pic0 = NULL;
#endif /* X11 */
/****************************SUBROUTINES********************************/
stoplines() /* turn off the drawing of connected lines */
{
#ifdef X11
startpt = NULL;
#else
x_c = -9999.0;
#endif /* X11 */
return;
}
fetchPic(addFlag)
int addFlag;
/* This routine is for fetching a picture from *DiskFileName and loading it in
pic[]; previous contents of pic1[] are obliterated; the assumption is made
that the number of horizontal lines(= corerows in number) used in making
the the picture saved in the file is the same as currently being used; this
should be changed */
{
#ifdef X11
printf("Disk i/o of pictures is not yet implemented\n");
#else
unsigned coord;
double corewdth,
scrnwdth;
double col_ratio;
double row_ratio;
int cflag = NO,
numColorPlanes;
int eight_rows;
int i,
k,
m;
int fgetc(); /* this is a function; getc() is not */
char getNextChar();
char colorByte = color;
char picChar;
char docstr[82];
char *cp,
*fgets(); /* recall fgets does return the carriage return
*/
#ifdef DEBUG
fprintf(stderr, "fetchPic(%d): level=%d file=%s\n", addFlag, level,
DiskFileName);
pause(1.5);
#endif /* DEBUG */
if(colorPlanes == 0 && level == 2) {
PRINT
"You do not have the memory to store this picture. Use while plotting\n");
PRINT
"by hitting : and then using command FD or AFD \n");
return;
}
picNameFlag = YES; /* records the fact that this file has been
accessed; */
#ifdef DESMET
gp = fopen(DiskFileName, OPENFORREADING);/* open to "r" read */
#endif /* DESMET */
#ifdef MS
gp = fopen(DiskFileName, "rb");/* open to "rb" read binary */
#endif /* MS */
if(gp == NULL) {
PRINT
"The program cannot open %s. Perhaps the name is wrong \n"
,DiskFileName);
return;
}
do {
cp = fgets(docstr, 82, gp);
if(cp == 0) {
PRINT "read error \n");
return;
}
} while(docstr[0] != '#');
/* fgets gets a new line and returns 0 on end
of file or on error; the last line of text
starts with '#' */
if(docstr[1] == '4')
sscanf(docstr + 2, "%d %d %d\n", &corecols, &corerows,
&numColorPlanes);
else {
if(docstr[1] == 'c')
cflag = YES;/* = c means compressed */
sscanf(docstr + 2, "%d %d \n", &corecols, &corerows);
}
corewdth = corecols;
scrnwdth = scrncols;
col_ratio = scrnwdth / corewdth;
row_ratio = scrnrows / (8.* corerows);/* note decimal point */
#ifndef MAINFRAME
if(level >= PROCESS && addFlag == NO) {
scr_clr(); /* in desmets pcio.a */
if(printer == 3)
bottomPrint();
}
#endif /* MAINFRAME */
if(docstr[1] != '4') {
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
/* coord = m*corerows+k; */
/* pic1[coord]= fgetc(gp); */
if(cflag == NO)/* not compressed */
picChar = fgetc(gp);
else {
picChar = getNextChar(gp);
/* for compressed files */
}
if(addFlag == NO) {
if(colorPlanes >= 4) {
/* need colorByte parens below because
!= is carried out before & */
pic8[coord] = ((colorByte & eight) ? picChar : 0);
pic4[coord] = ((colorByte & four) ? picChar : 0);
pic2[coord] = ((colorByte & two) ? picChar : 0);
pic1[coord] = ((colorByte & one) ? picChar : 0);
}
else
if(colorPlanes >= 1) {
pic1[coord] = ((colorByte & one) ? picChar : 0);
}
}
if(addFlag == YES) {
/* means the picture gets added in to whatever
is present */
if(colorPlanes >= 4) {
if((colorByte & eight) != 0)
/* need colorByte parens because != is carried
out before & */
pic8[coord] = pic8[coord] | picChar;
if((colorByte & four) != 0)
pic4[coord] = pic4[coord] | picChar;
if((colorByte & two) != 0)
pic2[coord] = pic2[coord] | picChar;
if((colorByte & one) != 0)
pic1[coord] = pic1[coord] | picChar;
}
else
if(colorPlanes >= 1) {
pic1[coord] = pic1[coord] | picChar;
}
}
/* now add byte to screen; same as in add_to_pic() */
if(level >= PROCESS) {
/* coord = ColTimesCorerows+row; */
eight_rows = 8 * k;/* k = row */
for(rowbit = 0; rowbit < 8; rowbit++)
if((picChar & mask[rowbit]) != 0) {
/* this examines the specific bit in pic1[] to
see if it is 0 */
COL = col_ratio * m;
/* m = col */
ROW = (eight_rows + rowbit) * row_ratio;
setPixel(COL, ROW, color);
/* this is part of the Desmet graphics package;
it writes a dot on the screen */
/* in MSC, the 3rd variable in
setPixel is a dumby and
changes in the color must be
set independently */
}
}/* end if level */
}
}
if(docstr[1] == '4' && colorPlanes < 4) {
if(addFlag == NO)
clearp();
for(i = 0; i < 4; i++) {
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic1[coord] |= getNextChar(gp);
/* for compressed files */
}
}
if(level > 2) {
boot = 1;
boot_crt();
}
}
if(docstr[1] == '4' && addFlag == NO && colorPlanes >= 4) {
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic1[coord] = getNextChar(gp);
/* for compressed files */
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic2[coord] = getNextChar(gp);
/* for compressed files */
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic4[coord] = getNextChar(gp);
/* for compressed files */
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic8[coord] = getNextChar(gp);
/* for compressed files */
}
if(level > 2) {
boot = 1;
boot_crt();
}
}
if(docstr[1] == '4' && addFlag == YES) {
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic1[coord] = getNextChar(gp) | pic1[coord];
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic2[coord] = getNextChar(gp) | pic2[coord];
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic4[coord] = getNextChar(gp) | pic4[coord];
}
byteCount = 0;
for(k = 0; k < corerows; k++)
for(m = 0; m < corecols; m++) {
coord = m * corerows + k;
pic8[coord] = getNextChar(gp) | pic8[coord];
}
if(level > 2) {
boot = 1;
boot_crt();
}
}
fclose(gp);
#endif /* X11 */
}
#ifndef X11
int picAlloc()
{ /* returns the number of planes; pic has already been allocated */
int i;
if((pic1 = (char far *) _fmalloc(CORESIZE * sizeof(char))) == NULL)
return(0);
if((pic2 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
return(1);
if((pic4 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
return(2);
if((pic8 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
return(3);
i = 4;
/*
while((pic0 = (char far *) _fmalloc(sizeof(char)*1000)) != NULL)
i++;
*/
return(i);
}
plot(x1, y1) /* This plots a point on the screen AND sets a
bit to 1 in the matrix pic1[], provided
x1,y1 is within the window to be plotted. If
it is not within the window and if
"diameter" is > 0, the routine checks to see
if it is within "diameters[ScrnSec]" times
the width and within "diameters[ScrnSec]
times the height of the screen. If it is not
close enough to the screen based on this
criterion, the program is reset to SINGLE
STEP mode to prevent overflow; the screen
coordinates used: ROW,COL are preserved
since they are external */
double x1,
y1;
{
char maskByte;
unsigned ROWcoord;
double d,
dd,
xdif,
ydif,
xx,
yy;
/* sCOL and sROW are for drawing lines */
sCOL = COL = xScrPix[ScrnSec] * ((xx = x1 - X_lower));
sROW = ROW = yScrPix[ScrnSec] * ((yy = Y_upper - y1));
if((X_upper - x1) * xx < 0 || yy * (Y_lower - y1) > 0) {
/* if outside screen */
stoplines(); /* for stopping drawing connected lines */
xdif = X_upper - X_lower;/* this could be defined once */
ydif = Y_upper - Y_lower;
d = diameters[ScrnSec];
dd = d * (1 + d);
if(d >= 0) {
if((X_upper - x1) * xx > dd * xdif * xdif
|| yy * (Y_lower - y1) > dd * ydif * ydif) {
PlotComplaint();
}
}
return;
}
if(windowflag[0] == ON && ScrnSec == 0) {
if(windowflag[1] == ON)
if(COL <= halfscrcols && ROW <= halfscrrows) {
setCoreCOLROW(x1, y1);
/* sets COL and ROW for Core for connectp */
return;/* if inside window ss */
}
if(windowflag[2] == ON)
if(COL >= halfscrcols && ROW <= halfscrrows) {
setCoreCOLROW(x1, y1);
/* sets COL and ROW for Core for connectp */
return;/* if inside window ss */
}
if(windowflag[3] == ON)
if(COL <= halfscrcols && ROW >= halfscrrows) {
setCoreCOLROW(x1, y1);
/* sets COL and ROW for Core for connectp */
return;/* if inside window ss */
}
if(windowflag[4] == ON)
if(COL >= halfscrcols && ROW >= halfscrrows) {
setCoreCOLROW(x1, y1);
/* sets COL and ROW for Core for connectp */
return;/* if inside window ss */
}
}
else
if(ScrnSec != 0) {
FindPixel(x1, y1, SCRN);
sCOL = COL;/* sCOL and sROW are for drawing lines */
sROW = ROW;
}
/* this routine puts the coordinates in the vector COL,ROW;*/
if(IsCross0Set == YES) {
/* if the cross is not turned off, and the new
dot to be plotted is in the cross, it will
cause erased when the cross goes */
turnoff(BIGCROSS);
}
setPixel(COL, ROW, color);
/* this is part of the Desmet graphics package;
it writes a dot on the screen; it is about
10% faster than inline execution of Bob
Buchal's write_dot() */
/* in MSC, the 3rd variable in setPixel is a dumby and changes in the color
must be set independently */
#ifndef MAINFRAME
if(cross0flag == 1) /* set using interrupt 'k' */
SetCross(BIGCROSS);
#endif /* ifndef MAINFRAME */
/* now plot point on the internal memory copy of the picture */
if(ScrnSec == 0) {
COL = (*xCorPix) * xx;
ROW = (*yCorPix) * yy;
}
else
FindPixel(x1, y1, CORE);
maskByte = mask[(ROW % 8)];
ROWcoord = COL * corerows + ROW / 8;
corePixel(ROWcoord, maskByte);
/* this colors a core pixel as specified by
coord the color "color" */
}
setCoreCOLROW(x1, y1) /* sets COL and ROW for Core for connectp */
double x1,
y1;
{
if(ScrnSec == 0) {
COL = (*xCorPix) * (x1 - X_lower);
ROW = (*yCorPix) * (Y_upper - y1);
}
else
FindPixel(x1, y1, CORE);/* sets COL and ROW */
}
PlotComplaint() { /* called by plot() */
scr_rowcol(1, 0);
PRINT
"X = %15.12lf Y = %15.12lf \n", y[X_coord], y[Y_coord]);
PRINT
"This point is too far from screen: more than %lf diameters from the screen\n",
diameters[ScrnSec]);
#ifndef MAINFRAME
PRINT
"Program now enters SINGLE STEP mode to prevent overflow\n");
PRINT
"Reinitialize using 'i' or 'm' or cursor keys and/or reset menu's parameters\n"
);
#endif /* ifndef MAINFRAME */
PRINT
"\nTo change 'diameters', use command SD \n"
);
#ifndef MAINFRAME
cycle = 2; /* single step mode; setting cycle = 2 tells
Interrupt() not to call plot() since that
would give an infinite loop */
Interrupt();
#else
/* This is what we do in MAINFRAME mode in case of overflow */
taskFlag = -1; /* this means that when plotsomething() is
called, we do not plot a dot */
level = 2;
PRINT "DROPPING BACK TO MENU DUE TO LEAVING BOX");
#endif /* ifndef MAINFRAME */
}
clrWindow() {
stoplines(); /* for stopping drawing connected lines */
SignIsOn = 0; /* sign about jump size */
IsCross0Set = NO; /* screen cross at y0 is not set */
IsCross1Set = NO; /* screen cross at y1 is not set */
if(ScrnSec == 0) {
scr_clr(); /* in desmets pcio.a */
clearp();
}
if(ScrnSec == 1) {
picOff(0, 0, corecols / 2, corerows / 2);
scrOff(0, 0, scrncols / 2, scrnrows / 2);
}
if(ScrnSec == 2) {
picOff(corecols / 2, 0, corecols, corerows / 2);
scrOff(scrncols / 2, 0, scrncols, scrnrows / 2);
}
if(ScrnSec == 3) {
picOff(0, corerows / 2, corecols / 2, corerows);
scrOff(0, scrnrows / 2, scrncols / 2, scrnrows);
}
if(ScrnSec == 4) {
picOff(corecols / 2, corerows / 2, corecols, corerows);
scrOff(scrncols / 2, scrnrows / 2, scrncols, scrnrows);
}
}
ticMarks(flag) /* called by draw_box when ticFlag == ON; flag
= 2 means that an extra fine set of tic
marks should be drawn with 1/5 the spacing;
the extra set is small and should show up
better when the picture is printed */
int flag;
{
int size = 100,
sign;
double gap,
ticGap(), x, v;
double moduloAB();
scr_rowcol(2, 0);
if(flag == 2)
size = 170;
gap = ticGap(X_upp - X_low);
if(gap == 0) {
PRINT "CANNOT DRAW TIC MARKS; BOX HAS 0 WIDTH \n");
return;
}
if(flag == 2)
gap = gap *.2;
x = X_low - moduloAB(X_low, 0., gap) + gap;
/* moduloAB() is a number between 0. and gap,
-- even if gap is negative */
x = x + gap *.000001;
erase_line();
PRINT "Horizontal spacing between tic marks: %lf starting at %lf\n"
,gap, x);
if(X_upp < X_low)
sign = -1;
else
sign = 1;
for(; sign * (X_upp - x) > 0; x += gap) {/* top and bottom */
/*
= HORIZSCRN 3 means horizontal line segment on screen
= VERTSCRN 4 means vertical line segment on screen
= HORIZCORE 5 means horizontal line segment on core
= VERTCORE 6 means vertical line segment on core
*/
plotY =.99999 * Y_upp +.00001 * Y_low;
drawcross(x, plotY, corecols / size, 8 * corerows / size, VERTCORE);
/* permanent cross in core */
drawcross(x, plotY, scrncols / size, scrnrows / size, VERTSCRN);
/* permanent cross in crt */
plotY =.99999 * Y_low +.00001 * Y_upp;
drawcross(x, plotY, corecols / size, (8 * corerows) / size, VERTCORE);
drawcross(x, plotY, scrncols / size, scrnrows / size, VERTSCRN);
}
gap = ticGap(Y_upp - Y_low);/* has same sign as argument of ticGap */
if(gap == 0) {
PRINT "CANNOT DRAW TIC MARKS; BOX HAS 0 HEIGHT \n");
return;
}
if(flag == 2)
gap = gap *.2;
v = Y_low - moduloAB(Y_low, 0., gap) + gap;
v = v + gap *.000001;
PRINT "Vertical spacing between tic marks: %lf starting at %lf\n"
,gap, v);
if(Y_upp < Y_low)
sign = -1;
else
sign = 1;
for(; sign * (Y_upp - v) > 0; v += gap) {/* sides */
plotX =.99999 * X_upp +.00001 * X_low;
drawcross(plotX, v, corecols / size, (8 * corerows) / size, HORIZCORE);
drawcross(plotX, v, scrncols / size, scrnrows / size, HORIZSCRN);
plotX =.99999 * X_low +.00001 * X_upp;
drawcross(plotX, v, corecols / size, (8 * corerows) / size, HORIZCORE);
drawcross(plotX, v, scrncols / size, scrnrows / size, HORIZSCRN);
}
}
double ticGap(dif) /* returns distance between tic marks; input
difference between left and right scales;
returns a number starting with a digit
5,6,7,8, or 9; Hence .0056... returns .005,
and -.0056 becomes -.005; if first digit is
1, number is multiplied by 5; if first digit
is less than 5, number is multiplied by 2;
*/
double dif;
{
double old = dif; /* keeps track of change in size of dif */
if(dif == 0)
return(0.);
if(dif < 0)
dif = -dif;
while(dif < 1)
dif = 10 * dif;
while(dif > 10)
dif = dif / 10;
if(dif < 2)
dif = dif * 5.;
if(dif < 5)
dif = dif * 2.;
dif = 1./ (dif / old);
return(dif);
}
connect2 (x1, y1, x2, y2)
double x1,
y1,
x2,
y2;
{
int flag0,
flagm;
flag0 = cross0flag; /* when cross0flag = YES, the large cross will
be plotted at each dot, and erased before
the next cross is drawn */
cross0flag = NO;
flagm = modFlag;
modFlag = NO; /* used for drawing boxes in case a mod has
been hit */
plot(x1, y1);
connectp(x1, y1); /* this is needed for setting constants; see
also draw_box() */
connectp(x2, y2);
stoplines(); /* for stopping drawing connected lines */
cross0flag = flag0;
modFlag = flagm;
}
connectp(x, y) /* connects x,y to x_c,y_c; you must have
called plot(x_c,y_c) because this routine
sets sCOL and sROW which are for drawing
lines; see connect2() for an example of how
to call it. This routine is temporarily
turned off by setting x_c t0 -9999. */
/* **** note the following definitions from ScreenConstants(): xDifRecip =
1/fabs(X_upper-X_lower); yDifRecip = 1/fabs(Y_upper-Y_lower); sCOL and
sROW are set by plot, so a point must be plotted before using connect ******
*/
double x,
y;
{
char maskByte;
unsigned coord;
int xpix,
ypix;
int oldsCOL,
oldsROW,
oldcCOL,
oldcROW,
temp;
int n,
abs();
int maximum,
xp,
yp;
long CoreColDif,
CoreRowDif;
long coldif,
rowdif;
double fabs(), xfraction, yfraction, Old_x_c;
xfraction = fabs(x - x_c) * xDifRecip;
xp = corecols * xfraction;
yfraction = fabs(y - y_c) * yDifRecip;
yp = core_row_bits * yfraction;
if((maximum = xp) < yp)
maximum = yp;
oldsCOL = sCOL;
oldsROW = sROW;
oldcCOL = COL;
oldcROW = ROW;
/* in cases where there is a big change in x or y because of evaluating
something modulo something, we jump */
Old_x_c = x_c;
x_c = x;
y_c = y;
plot(x, y); /* this sets x_c = -9999 if x,y is outside its
frame; it also can set x_c = -9999. */
if(x_c == -9999.|| Old_x_c == -9999.
|| modFlag == YES
|| maximum < 2) {
return;
}
else {
/* first SCREEN line */
coldif = sCOL - oldsCOL;
rowdif = sROW - oldsROW;
if(coldif >= abs(rowdif))/* in particular coldif > 0 */
for(n = 1; n < coldif; n++) {
temp = (rowdif * n) / coldif;
setPixel(oldsCOL + n, oldsROW + temp, color);
/* in MSC, the 3rd variable in setPixel is a dumby and
changes in the color must be set independently */
} /* in MSC, the 3rd variable is a dumby and
changes in the color must be set
independently */
else if(-coldif >= abs(rowdif))
/* in particular coldif > 0 */
for(n = -1; n > coldif; n--) {
temp = (rowdif * n) / coldif;
setPixel(oldsCOL + n, oldsROW + temp, color);
}
else if(rowdif >= abs(coldif))
/* in particular rowdif > 0 */
for(n = 1; n < rowdif; n++) {
temp = (coldif * n) / rowdif;
setPixel(oldsCOL + temp, oldsROW + n, color);
}
else if(-rowdif >= abs(coldif))
/* in particular coldif > 0 */
for(n = -1; n > rowdif; n--) {
temp = (coldif * n) / rowdif;
setPixel(oldsCOL + temp, oldsROW + n, color);
}
/* now CORE line */
CoreColDif = COL - oldcCOL;
CoreRowDif = ROW - oldcROW;
if(CoreColDif >= abs(CoreRowDif))
/* in particular CoreColDif > 0 */
for(n = 1; n < CoreColDif; n++) {
temp = (CoreRowDif * n) / CoreColDif;
xpix = oldcCOL + n;
ypix = oldcROW + temp;
coord = xpix * corerows + ypix / 8;
maskByte = mask[ypix % 8];
corePixel(coord, maskByte);
/* this colors a core(=pic) pixel as specified
by coord the color "color" */
}
else if(-CoreColDif >= abs(CoreRowDif))
for(n = -1; n > CoreColDif; n--) {
temp = (CoreRowDif * n) / CoreColDif;
xpix = oldcCOL + n;
ypix = oldcROW + temp;
coord = xpix * corerows + ypix / 8;
maskByte = mask[ypix % 8];
corePixel(coord, maskByte);
/* this colors a core(=pic) pixel as specified
by coord the color "color" */
}
else if(CoreRowDif >= abs(CoreColDif))
for(n = 1; n < CoreRowDif; n++) {
temp = (CoreColDif * n) / CoreRowDif;
xpix = oldcCOL + temp;
ypix = oldcROW + n;
coord = xpix * corerows + ypix / 8;
maskByte = mask[ypix % 8];
corePixel(coord, maskByte);
/* this colors a core(=pic) pixel as specified
by coord the color "color" */
}
else if(-CoreRowDif >= abs(CoreColDif))
for(n = -1; n > CoreRowDif; n--) {
temp = (CoreColDif * n) / CoreRowDif;
xpix = oldcCOL + temp;
ypix = oldcROW + n;
coord = xpix * corerows + ypix / 8;
maskByte = mask[ypix % 8];
corePixel(coord, maskByte);
/* this colors a core(=pic) pixel as specified
by coord the color "color" */
}
}
}
#ifndef unix
#include <conio.h>
#endif /* unix */
scrOff(COLnum1, ROWnum1, COLnum2, ROWnum2)
int COLnum1,
ROWnum1,
COLnum2,
ROWnum2;
{
#ifndef MAINFRAME
_setcolor(BLANK);
_rectangle(_GFILLINTERIOR, COLnum1, ROWnum1, COLnum2, ROWnum2);
_setcolor(color);
#endif /* ifndef MAINFRAME */
}
picOff(COLnum1, ROWnum1, COLnum2, ROWnum2)/* CORE COPY; see also scrOff();
each row is a row of bytes */
int COLnum1,
ROWnum1,
COLnum2,
ROWnum2;
{
unsigned coord;
int ROWdif = ROWnum2 - ROWnum1;
for(COL = COLnum1; COL < COLnum2; COL++) {
coord = COL * corerows + ROWnum1;
#ifdef DESMET
_setmem(pic1 + coord, ROWdif, 0);
#endif /* DESMET */
#ifdef MS
clearline(coord, ROWdif);
/* this is written as a function to optimize
register allocation */
#endif /* MS */
}
}
#ifdef MS
clearline(coord, ROWdif) /* this is separated out to make use of
automatic register variables in loops; this
is the routine that must be sped up */
int ROWdif;
unsigned coord;
{
unsigned cd;
int end;
char far * pp1;
char far * pp2;
char far * pp4;
char far * pp8;
end = coord + ROWdif;
if(colorPlanes == 0)
return;
if(colorPlanes >= 4) {
pp1 = pic1 + coord;
pp2 = pic2 + coord;
pp4 = pic4 + coord;
pp8 = pic8 + coord;
for(cd = coord; cd < end; cd++) {
*(pp1++) = 0;
*(pp2++) = 0;
*(pp4++) = 0;
*(pp8++) = 0;
}
}
else
if(colorPlanes >= 1) {
for(pp1 = pic1 + coord, cd = coord; cd < end; cd++)
*(pp1++) = 0;
}
}
#endif /* MS */
block_plot(x1, x2, y1, y2) /* This plots a point on the screen AND sets a
bit to 1 in the matrix pic1[]. */
float x1,
x2,
y1,
y2;
{
unsigned coord;
long ROW2,
COLnum1,
COLnum2,
ROWnum1,
ROWnum2;
FindPixel((double)x1, (double)y1, SCRN);/*sets COL and ROW */
/* this routine puts the coordinates in the vector COL,ROW; */
COLnum1 = COL;
ROWnum1 = ROW;
FindPixel((double)x2, (double)y2, SCRN);
COLnum2 = COL;
ROWnum2 = ROW;
if((X_upper -x1)*(X_lower -x1) <= 0 && (Y_upper -y1)*(Y_lower -y1) <=0)
{
for(COL = COLnum1; COL < COLnum2; COL++)/* COL is an int */
for(ROW = ROWnum1; ROW < ROWnum2; ROW++) {
#ifndef MAINFRAME
setPixel(COL, ROW, color);
/* this is part of the Desmet graphics package;
it writes a dot on the screen */
/* in MSC, the 3rd variable in setPixel is a dumby and
changes in the color must be set independently */
#endif /* MAINFRAME */
}
}
else
return;
/* now plot points on the internal memory copy of the picture */
FindPixel((double)x1, (double)y1, CORE);
COLnum1 = COL;
ROWnum1 = ROW;
FindPixel((double)x2, (double)y2, CORE);
COLnum2 = COL;
ROWnum2 = ROW;
for(COL = COLnum1; COL < COLnum2; COL++)
for(ROW2 = ROWnum1; ROW2 < ROWnum2; ROW2++)
if(COL >= 0 && COL < corecols
&& ROW2 >= 0 && ROW2 < core_row_bits) {
coord = COL * corerows + (ROW2 / 8);
corePixel(coord, mask[(ROW2 % 8)]);
/* this colors a core(=pic) pixel as specified by
coord the color "color" */
}
}
boot_crt() { /* This is for use with input -99, 99, -699,
699, etc, in parameter menu ... ; it does
depends on whether "boot" is 0 or 1;first it
calculates the constants needed to plot
points, constants that are needed by
"plot()";if "boot" is 0, the screen and
pic1[] are cleared; when "boot" = 1; the
picture in pic1[] is put on the screen; in
particular when a picture has been made and
the program returns to the menu, there is
still a copy of the picture in pic1[] and
this routine reboots it to the screen; if
"boxx" == 1, it draws a box; */
unsigned coord;
char pc1,
pc2,
pc4,
pc8,
maskByte,
pc;
int ColTimesCorerows;
int col,
row,
eight_rows,
i;
double col_ratio,
row_ratio;
double corewdth,
scrnwdth;
int int1 = 1,
int2 = 2,
int4 = 4,
int8 = 8;
int prevColor = color,
activeColor = color;
ScreenConstants(); /* defines ax,bx where x = 0,00,1,2 */
corewdth = corecols;
scrnwdth = scrncols;
IsCross0Set = NO; /* screen cross at y0 is not set */
IsCross1Set = NO; /* screen cross at y1 is not set */
#ifndef MAINFRAME
scr_clr(); /* in desmets pcio.a */
if(printer == 3)
bottomPrint();
#endif /* MAINFRAME */
if(boot == 0)
clearp();
if(boot == 0 && ScrnSec == 0) {
/* this turns window overlap prevention off */
for(i = 0; i <= 4; i++)
windowflag[i] = OFF;
}
pc1 = pc2 = pc4 = pc8 = 0;
col_ratio = scrnwdth / corewdth;
row_ratio = scrnrows / (8.* corerows);/* note decimal point */
if(boot != 0 && colorPlanes > 1)
{ for(col = 0; col < corecols; col++)
{ COL = col_ratio * col;
for(eight_rows = 0, row = 0, coord = col * corerows
; row < corerows
; coord++, row++, eight_rows += 8)
{
pc1 = pic1[coord];
pc2 = pic2[coord];
if(colorPlanes >= 3)
pc4 = pic4[coord];
if(colorPlanes >= 4)
pc8 = pic8[coord];
if((pc = pc1 | pc2 | pc4 | pc8) != 0)
{ for(rowbit = 0; rowbit < 8; rowbit++)
{ maskByte = mask[rowbit];
if(pc & maskByte) /* i.e. if non zero */
{ color = ((pc1 & maskByte) ? int1 : 0)
+ ((pc2 & maskByte) ? int2 : 0)
+ ((pc4 & maskByte) ? int4 : 0)
+ ((pc8 & maskByte) ? int8 : 0);
if(color != prevColor)
{ _setcolor(color);
prevColor = color;
}
ROW = (eight_rows + rowbit) * row_ratio;
setPixel(COL, ROW, color);
/* in MSC, the 3rd variable in
setPixel is a dumby and
changes in the color must be
set independently */
}
}/* end for */
}/* end if pc */
}/* end for(eight_rows = 0... */
} /* end: for col, for row, and if */
}/* end if boot */
if(boot != 0 && colorPlanes == 1)
{ for(col = 0; col < corecols; col++)
{ COL = col_ratio * col;
ColTimesCorerows = col * corerows;
for(eight_rows = 0, row = 0, coord = ColTimesCorerows
; row < corerows
; coord++, row++, eight_rows += 8) {
if((pc = pic1[coord]) != 0) {
for(rowbit = 0; rowbit < 8; rowbit++) {
maskByte = mask[rowbit];
if(pc & maskByte)/*i.e. if non zero */
{ ROW =
(eight_rows + rowbit) * row_ratio;
setPixel(COL,ROW, color);
/* in MSC, the 3rd variable in
setPixel is a dumby and
changes in the color must be
set independently */
}
}/* end if */
}
}
} /* end: for col, for row, and if */
}
boot = 0;
if(boxx == 1)
draw_box();
color = activeColor;
_setcolor(color);
}
bottomPrint()
{
scr_rowcol(11,0); /* move cursor to bottom left; */
PRINT
"INTERRUPT MENU (* for help)\n");
PRINT
"spacebar return to Menu \n");
PRINT
"*A Actions menu \n");
PRINT
"*S Screen menu \n");
PRINT
"*H Help level menu \n");
}
corePixel(coord, maskByte) /* this colors a core(=pic) pixel as specified
by coord the color "color" */
unsigned coord;
char maskByte;
{
char colorByte = color%16;/* color mod 16 */
if(colorPlanes == 0)
return;
if(colorPlanes >= 4) {
pic1[coord] = ((colorByte & one)
? pic1[coord] | maskByte
: pic1[coord] & ~maskByte);
pic2[coord] = ((colorByte & two)
? pic2[coord] | maskByte
: pic2[coord] & ~maskByte);
pic4[coord] = ((colorByte & four)
? pic4[coord] | maskByte
: pic4[coord] & ~maskByte);
pic8[coord] = ((colorByte & eight)
? pic8[coord] | maskByte
: pic8[coord] & ~maskByte);
}
else
if(colorPlanes >= 1) {
pic1[coord] = ((colorByte & one)
? pic1[coord] | maskByte
: pic1[coord] & ~maskByte);
/* pic1[coord]= pic1[coord] | maskByte;*/
}
}
char getNextChar(gp)
FILE *gp;
{
int fgetc(); /* this is a function; getc() is not */
if(byteCount != 0) {
byteCount--;
return(lastByte);
}
if(byteCount == 0) {
C = fgetc(gp);
if(C == 0 || C == byte255) {
lastByte = C;
byteCount = fgetc(gp) - 1;
if(byteCount < 0)
byteCount += 256;
return(C);
}
else
return(C);
}
return(C); /* we will not get here */
}
FindPixel(xx, yy, picnum) /* this routine puts the coordinates in the
vector COL,ROW; if picnum == SCRN == 1,
they are for the crt while if= CORE = 2, they are for the core
copy */
double xx,
yy;
int picnum;
{
int x,
y;
xx -= X_lower;
yy -= Y_upper; /* notce the sign is incorrect here but this
will be made up for with the omission of a
sign later */
if(picnum == SCRN) { /* crt */
xmax = scrncols;
ymax = scrnrows;
x = xScrPix[ScrnSec] * xx;
y = -yScrPix[ScrnSec] * yy;
}
else if(picnum == CORE) { /* core */
xmax = corecols;
ymax = core_row_bits;
x = xCorPix[ScrnSec] * xx;
y = -yCorPix[ScrnSec] * yy;
}
switch(ScrnSec) {
case 1: /* upper left */
x = x / 2;
y = y / 2;
break;
case 2: /* upper right */
x = (x + xmax) / 2;
y = y / 2;
break;
case 3: /* lower left */
x = x / 2;
y = (y + ymax) / 2;
break;
case 4: /* lower right */
x = (x + xmax) / 2;
y = (y + ymax) / 2;
break;
case 0:
break;
}
COL = x;
ROW = y;
return;
}
clearp() { /* Sets matrix pic1[] = zero */
#ifdef DESMET
_setmem(pic1, CORESIZE, 0);
#endif /* DESMET */
#ifdef MS
unsigned cd,
coresize = CORESIZE;
if(colorPlanes >= 4)
for(cd = 0; cd < coresize; cd++) {
pic1[cd] = pic2[cd] = pic4[cd] = pic8[cd] = 0;
}
else
if(colorPlanes >= 1)
for(cd = 0; cd < coresize; cd++) {
pic1[cd] = 0;
}
#endif /* MS */
if(TDFreq != 0) {
TDFreq = 0;
erase_line();
PRINT
"****** TDFreq set = 0; picture will not automatically be stored. ********\n");
}
if(TDTime != 0) {
TDTime = 0;
erase_line();
PRINT
"****** TDTIME set = 0; picture will not automatically be stored. ********\n");
}
if(TDTime == 0 && runTime == 0)
timeFlag = NO;
}
draw_box() { /* draws a box with x coordinates X_low,X_upp
and y coordinates Y_low,Y_upp; enough pixels
are used to guarantee a solid line for both
the screen and pic1[] ( at least
vertically); routine now aims at getting
enough pixels plotted horizontally for
pic1[]; cross0flag is temporarily set to 0
so that no cross is drawn during the drawing
of the box */
int flag;
double X_small,
Y_small;
if(set_box() != 0) {
if(ticFlag > OFF)
ticMarks(1);
/* set_box() sets X_low thru Y_upp; set_box ==
0 if box is partially outside window */
if(ticFlag == 2)
ticMarks(2);
/* draws an extra set of fine tic marks */
}
PrintBoxCoordinates(); /* if printer > 1; prints at top of screen */
/* dots plotted at top and bottom of screen and pic1[] */
Y_small =.00001 * (Y_upp - Y_low);
X_small =.00001 * (X_upp - X_low);
flag = cross0flag; /* when cross0flag = 1, the large cross will be
plotted at each dot, and erased before the
next cross is drawn */
cross0flag = 0;
modFlag = NO; /* used for drawing boxes in case a mod has
been hit */
plot(X_low + X_small, Y_low + Y_small);
connectp(X_low + X_small, Y_low + Y_small);
connectp(X_upp - X_small, Y_low + Y_small);
connectp(X_upp - X_small, Y_upp - Y_small);
connectp(X_low + X_small, Y_upp - Y_small);
connectp(X_low + X_small, Y_low + Y_small);
stoplines(); /* for stopping drawing connected lines */
cross0flag = flag;
}
PrintBoxCoordinates() { /* if printer > 1; prints at top of screen */
scr_rowcol(20, 0);
if(printer > 1) {
set_box(); /* sets X_low thru Y_upp */
erase_line();
PRINT
"box coords: LEFT: %lf RIGHT: %lf BOTTOM: %lf TOP: %lf \n"
,X_low, X_upp, Y_low, Y_upp);
}
}
erase_line() { /* Under condition of SCREEN(see ydefines),
this prints a line of blanks on the screen
to ensure that when a new PARTIAL line is
printed, there will be no left over digits
and letters from a previous printing; notice
the cursor returns to the beginning of the
line -- that is there is no line feed */
#ifndef MAINFRAME
if(SCREEN) {
PRINT
" "
);
PRINT " \r");
}
#endif /* MAINFRAME */
}
definitely_erase_line() { /* This is for the case where we want a blank
line even though printer == 0; for use in
YINTRPT.C this prints a line of blanks on
the screen to ensure that when a new PARTIAL
line is printed, there will be no left over
digits and letters from a previous printing;
notice the cursor returns to the beginning
of the line -- that is there is no line feed
*/
#ifndef MAINFRAME
PRINT
" "
);
PRINT " \r");
#endif /* ifndef MAINFRAME */
}
maskdef(MASK)
char MASK[];
{
MASK[7] = 1;
MASK[6] = 2;
MASK[5] = 4;
MASK[4] = 8;
MASK[3] = 16;
MASK[2] = 32;
MASK[1] = 64;
MASK[0] = 128;
}
td() {
char C;
unsigned coord;
int p0,
i,
handleC();
if(colorPlanes == 0) {
PRINT
"You do not have the memory to keep a high resolution copy;\n");
PRINT
"Since it does not exist, it cannot be stored \n");
return;
}
#ifdef DESMET
fp = fopen(DiskFileName, "w");/* open to "w" write */
#endif /* DESMET */
#ifdef MS
fp = fopen(DiskFileName, "wb");/* append binary */
#endif /* MS */
if(fp == 0L) {
PRINT "CANNOT OPEN FILE %s; abort picture save\n"
,DiskFileName);
return;
}
if(level == 2)
scr_clr();
DumpData(fp);
/* fprintf(fp,"# 960 68 1\n"); */
fprintf(fp, "#4 %d %d %d\n", corecols, corerows, colorPlanes);
if(colorPlanes >= 1) {
byteCount = 0;
for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
for(i = 0; i < corecols; i++) {
coord = i * corerows + p0;
C = pic1[coord];
if(handleC(C, fp) == NO)
{
fclose(fp);
return;
}
}
/* now finish off case where there is a string of 0's or 255's */
if(byteCount != 0)
if(tryPutc(byteCount, fp) == NO)
{
fclose(fp);
return;
}
}
if(colorPlanes >= 2) {
byteCount = 0;
for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
for(i = 0; i < corecols; i++) {
coord = i * corerows + p0;
C = pic2[coord];
if(handleC(C, fp) == NO)
{
fclose(fp);
return;
}
}
/* now finish off case where there is a string of 0's or 255's */
if(byteCount != 0)
if(tryPutc(byteCount, fp) == NO)
{
fclose(fp);
return;
}
}
if(colorPlanes >= 3) {
byteCount = 0;
for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
for(i = 0; i < corecols; i++) {
coord = i * corerows + p0;
C = pic4[coord];
if(handleC(C, fp) == NO)
{
fclose(fp);
return;
}
}
/* now finish off case where there is a string of 0's or 255's */
if(byteCount != 0)
if(tryPutc(byteCount, fp) == NO)
{
fclose(fp);
return;
}
}
if(colorPlanes >= 4) {
byteCount = 0;
for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
for(i = 0; i < corecols; i++) {
coord = i * corerows + p0;
C = pic8[coord];
if(handleC(C, fp) == NO)
{
fclose(fp);
return;
}
}
/* now finish off case where there is a string of 0's or 255's */
if(byteCount != 0)
if(tryPutc(byteCount, fp) == NO)
{
fclose(fp);
return;
}
}
for(i = 0; i < 100; i++)/* pad end of file a bit with 0's */
if(tryPutc(C = 0, fp) == NO)/* returns no if file is full */
{
fclose(fp);
return;
}
for(i = 0; i < 100; i++) {/* pad end of file a bit with 0's */
if(tryPutc(C = 0, fp) == NO)/* returns no if file is full */
{
fclose(fp);
return;
}
if(tryPutc(byte255, fp) == NO)
/* returns no if file is full */
{
fclose(fp);
return;
}
}
fclose(fp);
if(level < PROCESS)
scr_clr();
if(level >= PROCESS) {
scr_rowcol(0, 0);
erase_line();
ret_erase_line(5);
scr_rowcol(3, 0);
PRINT
"============================================================================="
);
scr_rowcol(2, 0);
}
if(level < PROCESS)
MainMenu();
erase_line();
PRINT
" PICTURE HAS BEEN STORED IN DISKFILE: %s \n\n",
DiskFileName);
}
td0 () { /* does compress-- monochrome output */
char C;
char pc1,
pc2,
pc4,
pc8,
maskByte,
pc;
unsigned coord;
int p0,
i,
handleC();
FILE * fopen();
if(colorPlanes == 0) {
PRINT
"You do not have the memory to keep a high resolution copy;\n");
PRINT
"Since it does not exist, it cannot be stored \n");
return;
}
#ifdef DESMET
fp = fopen(DiskFileName, "w");/* open to "w" write */
#endif /* DESMET */
#ifdef MS
fp = fopen(DiskFileName, "wb");/* append binary */
#endif /* MS */
if(fp == 0L) {
PRINT "CANNOT OPEN FILE %s; abort picture save\n"
,DiskFileName);
return;
}
if(level == 2)
scr_clr();
DumpData(fp);
/* fprintf(fp,"# 960 68 1\n"); */
fprintf(fp, "#c %d %d \n", corecols, corerows);
for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
for(i = 0; i < corecols; i++) {
/* sends line to disk if disk ==1 */
coord = i * corerows + p0;
if(colorPlanes >= 1)
pc1 = pic1[coord];
else
pc1 = 0;
if(colorPlanes >= 2)
pc2 = pic2[coord];
else
pc2 = 0;
if(colorPlanes >= 3)
pc4 = pic4[coord];
else
pc4 = 0;
if(colorPlanes >= 4)
pc8 = pic8[coord];
else
pc8 = 0;
C = pc1 | pc2 | pc4 | pc8;
/* C = pic1[coord];old monochrome version */
if(handleC(C, fp) == NO)
{
fclose(fp);
return;
}
}
/* now finish off case where there is a string of 0's or 255's */
if(byteCount != 0)
if(tryPutc(byteCount, fp) == NO)
{
fclose(fp);
return;
}
fclose(fp);
if(level < PROCESS)
scr_clr();
if(level >= PROCESS) {
scr_rowcol(0, 0);
erase_line();
ret_erase_line(5);
scr_rowcol(3, 0);
PRINT
"============================================================================="
);
scr_rowcol(2, 0);
}
if(level < PROCESS)
MainMenu();
erase_line();
PRINT
" PICTURE HAS BEEN STORED IN DISKFILE: %s \n\n",
DiskFileName);
}
/* char byte255 = 255,byteCount = 0,lastByte;*/
int handleC(C, fp)
char C;
FILE * fp;
{
int tryPutc();
if(C != 0 && C != byte255) {
if(byteCount == 0) {
if(tryPutc(C, fp) == NO)
/* returns no if file is full */
return(NO);
return(YES);
}
else { /* byteCount != 0 */
if(tryPutc(byteCount, fp) == NO)
return(NO);
byteCount = 0;
if(tryPutc(C, fp) == NO)
return(NO);
return(YES);
}
}
else { /* C = 0 or 255 */
if(byteCount == 0) {
lastByte = C;
byteCount++;
if(tryPutc(C, fp) == NO)
return(NO);
return(YES);
}
else /* byteCount != 0 */
if(C != lastByte || byteCount == byte255) {
if(tryPutc(byteCount, fp) == NO)
return(NO);
byteCount = 1;
lastByte = C;
if(tryPutc(C, fp) == NO)
return(NO);
return(YES);
}
else {
byteCount++;
}
}
return(YES);
}
int tryPutc(ch, fp)
unsigned char ch;
FILE * fp;
{
if(putc(ch, fp) == EOF) {
/* this writes a character and if it encounters
an error, it returns EOF, but EOF may also
be the transmitted character so then we must
check */
if(ferror(fp) != 0) {/* 0 means no error */
fileFailureWarning();
return(NO);
}
}
return(YES);
}
fileFailureWarning() {
ret_erase_line(2);
PRINT
"\n****************ERROR ENCOUNTERED IN STORING PICTURE*****************\n");
PRINT
"THIS DISK DRIVE MAY BE OUT OF SPACE; TRY STORING THE FILE ON A \n");
PRINT
"DIFFERENT DRIVE BY SPECIFYING A DIFFERENT DRIVE IN FILE NAME; THAT IS, \n");
PRINT
"USE COMMAND \"DN\" WITH A FILE NAME, E.G., C:...\n");
PRINT
"Putting a blank formatted floppy in your drive might NOT work. \n");
ret_erase_line(2);
}
resetDiameters() { /* this routine resets the sets
"diameters[ScrnSec]" when the screen is
rescaled using 's' or 'u';
"diameters[ScrnSec]" is needed so that when
the trajectory gets too far away from the
region of interest, the process can be
stopped; this prevents overflow; when
changing the scale so that a small region
can be examined, it is necessary to reset
"diameters" to a correspondingly larger
value */
double maximum,
Xratio,
Yratio;
set_box();
Xratio = fabs((X_upp - X_low) / (X_upper - X_lower));
Yratio = fabs((Y_upp - Y_low) / (Y_upper - Y_lower));
maximum = 1.;
if(1 / Xratio > maximum)
maximum = 1 / Xratio;
if(1 / Yratio > maximum)
maximum = 1 / Yratio;
if(diameters[ScrnSec] >= 0)
diameters[ScrnSec] = maximum * (.5 + diameters[OldScrSec]) -.5;
/* diameters: Let d = diameters. Recall that the big window is d windows above
and below the screen, so if the screen in one coordinate(Y) runs from -1
to 1, then the big window runs from -2*d-1 to 2*d+1, while the new
presumably smaller window runs from -Yratio to + Yratio. The big window is
(2*d +1)/Yratio times bigger than the little window; if D is the new
diameter, then that must be 2D+1 times the little window; hence D =
.5*[(2*d + 1)/Yratio -1] = (d + .5)maximum -.5 If d < 0, we do not have
to change it because negative values simply means we should ignore it */
/*PRINT
"Xratio=%lf,Yratio=%lf,max=%lf,old diam =%lf new diam=%lf\n",
Xratio,Yratio,maximum,diameters[0],diameters[ScrnSec]);
*/
}
reverseCore(x, y) /* reverses the color( 0 or 1) of core pixel;
*/
int x,
y;
{
char pc,
maskByte;
unsigned row,
coord;
/* first reverse the relevant bit of pic1[] */
rowbit = y % 8;
row = y / 8;
coord = x * corerows + row;
maskByte = mask[rowbit];
if(colorPlanes >= 4) {
if(((pc = pic1[coord]) & maskByte) > 0)
pc = pc & ~mask[rowbit];
/* ~m is the complement of m so pc & ~m is the
character that is 0 if either pc or ~m is 0,
that is, the rowbit bit is set to 0 */
else /* if the bit is not now set, then set it */
pic1[coord] = pc | mask[rowbit];
if(((pc = pic2[coord]) & maskByte) > 0)
pc = pc & ~mask[rowbit];
/* ~m is the complement of m so pc & ~m is the
character that is 0 if either pc or ~m is 0,
that is, the rowbit bit is set to 0 */
else /* if the bit is not now set, then set it */
pic2[coord] = pc | mask[rowbit];
if(((pc = pic4[coord]) & maskByte) > 0)
pc = pc & ~mask[rowbit];
/* ~m is the complement of m so pc & ~m is the
character that is 0 if either pc or ~m is 0,
that is, the rowbit bit is set to 0 */
else /* if the bit is not now set, then set it */
pic4[coord] = pc | mask[rowbit];
if(((pc = pic8[coord]) & maskByte) > 0)
pc = pc & ~mask[rowbit];
/* ~m is the complement of m so pc & ~m is the
character that is 0 if either pc or ~m is 0,
that is, the rowbit bit is set to 0 */
else /* if the bit is not now set, then set it */
pic8[coord] = pc | mask[rowbit];
}
else
if(colorPlanes >= 1) {
if(((pc = pic1[coord]) & maskByte) > 0)
pc = pc & ~mask[rowbit];
/* ~m is the complement of m so pc & ~m is the
character that is 0 if either pc or ~m is 0,
that is, the rowbit bit is set to 0 */
else /* if the bit is not now set, then set it */
pic1[coord] = pc | mask[rowbit];
}
}
ScreenConstants() { /* defines ax,bx where x = 0,00,1,2; it is
called by boot_crt() and 's' and 'u' */
double f,
fabs();
int ss = ScrnSec;
/* In plot() COL = xScrPix*y[0]-b0 (screen col) */
xDifRecip = 1 / fabs(X_upper - X_lower);
yDifRecip = 1 / fabs(Y_upper - Y_lower);
X_Lo[ss] = X_lower;
X_Up[ss] = X_upper;
Y_Lo[ss] = Y_lower;
Y_Up[ss] = Y_upper;
halfscrcols = scrncols / 2;
halfscrrows = scrnrows / 2;
xScrPix[ScrnSec] = scrncols / (X_upper - X_lower);/* for screen */
xCorPix[ScrnSec] = corecols / (X_upper - X_lower);/* for printer */
/* In plot() ROW = -yScrPix*y[1]+b1 (screen row) */
f = Y_upper - Y_lower;
yScrPix[ScrnSec] = scrnrows / f;
yCorPix[ScrnSec] = 8.* corerows / f;
LeftScrEdge[0] = LeftScrEdge[1] = LeftScrEdge[3] = 0;
LeftScrEdge[2] = LeftScrEdge[4] = scrncols / 2;
RtScrEdge[0] = RtScrEdge[2] = RtScrEdge[4] = scrncols;
RtScrEdge[1] = RtScrEdge[3] = scrncols / 2;
TopScrEdge[0] = TopScrEdge[1] = TopScrEdge[2] = 0;
TopScrEdge[3] = TopScrEdge[4] = scrnrows / 2;
BotScrEdge[0] = BotScrEdge[3] = BotScrEdge[4] = scrnrows;
BotScrEdge[1] = BotScrEdge[2] = scrnrows / 2;
}
int set_box() { /* sets the for box edges X_low thru Y_upp to
be x_new_low thru y_new_upp when they have
been set(so they are not the default
values); when they have not been set the
current box edges are used: X_lower thru
Y_upper; notice that no check is made of
whether x_new_low is less than x_new_upp;
these names are misleading since they really
refer to left and right rather than which
coordinate is less than another; returns: 1
if box is inside(or equal to) window 0 if
outside */
X_low = x_new_low;
if(X_low == -9999)
X_low = X_lower;/* equals first argument unless it is -9999, in
which case it equals the second argument */
X_upp = x_new_upp;
if(X_upp == -9999)
X_upp = X_upper;
Y_low = y_new_low;
if(Y_low == -9999)
Y_low = Y_lower;
Y_upp = y_new_upp;
if(Y_upp == -9999)
Y_upp = Y_upper;
/* test location of box */
if((X_low - X_lower) * (X_upper - X_low) < 0
|| (Y_low - Y_lower) * (Y_upper - Y_low) < 0
|| (X_upp - X_lower) * (X_upper - X_upp) < 0
|| (Y_upp - Y_lower) * (Y_upper - Y_upp) < 0) {
scr_rowcol(3, 0);
erase_line();
PRINT "Box is at least partially outside window\n");
return(0);
}
return(1);
}
#endif /* X11 */